package com.yanqu.road.server.logic.bag;

import com.yanqu.road.entity.activity.tongbing.config.TongBingConfig;
import com.yanqu.road.entity.bag.UseGoodsResult;
import com.yanqu.road.entity.config.goods.GoodsInfo;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.tonbing.TonBingModule;
import com.yanqu.road.server.gameplayer.module.activity.tongbing.TongBingModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.tongbing.TongBingMgr;
import com.yanqu.road.server.protocol.GameErrorCode;

/**
 * 使用后添加统兵红包
 */
public class UseAddTongBingRedPacket extends BaseUseGoods {

	public UseAddTongBingRedPacket(GamePlayer player, GoodsInfo goodsInfo, long param) {
		super(player, goodsInfo, param);
	}

	@Override
	int checkUse(long count) {
		// 检测是否在有效期
		TongBingConfig config = TongBingMgr.getConfig();
		if (config == null || !ActivityMgr.activityInShowTime(config.getActivityInfo())) {
			return GameErrorCode.E_ACTIVITY_NO_FOUND;
		}
		if (!config.inEnterActivityTime()) {
			return GameErrorCode.E_TONG_BING_NO_OPERATE_TIME;
		}
		return 0;
	}

	@Override
	UseGoodsResult executeUse(long count) {
		UseGoodsResult result = new UseGoodsResult();
		player.getModule(TongBingModule.class).addCrossRedPacket(goodsInfo,count);
		result.setReward("");
		return result;
	}
}
